package deibay.client.gui;

import java.awt.Dimension;

import javax.swing.JPanel;
import javax.swing.UIManager;

import org.jdesktop.swingx.JXFrame;

import deibay.client.core.views.IViewAdvertise;
import javax.swing.JButton;
import java.awt.Rectangle;
import java.awt.event.ActionListener;

import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class AdvertiseView extends JXFrame implements IViewAdvertise{

	private JPanel main = null;
	private JButton submitButton = null;
	private JScrollPane messageScroll = null;
	private JTextArea messageField = null;
	
	
	public AdvertiseView()
	{
		super();
		initialize();
	}
	
	private void initialize()
	{
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			e.printStackTrace();
		} 
		setTitle("Send Advertise");		
		setSize(new Dimension(400, 300));
		setContentPane(getMainPane());
		setVisible(true);
	}
	
	private JPanel getMainPane() {
		if(main == null)
		{
			main = new JPanel();
			main.setSize(520, 520);
			main.setLayout(null);		
			main.add(getSubmitButton(), null);
			main.add(getMessageScroll(), null);
		}
		return main;
	}

	public void close() {
		this.setVisible(false);
	}

	/**
	 * This method initializes submitButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getSubmitButton() {
		if (submitButton == null) {
			submitButton = new JButton();
			submitButton.setText("Send");
			submitButton.setBounds(new Rectangle(300, 200, 75, 20));
		}
		return submitButton;
	}

	/**
	 * This method initializes messageScroll	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getMessageScroll() {
		if (messageScroll == null) {
			messageScroll = new JScrollPane();
			messageScroll.setBounds(new Rectangle(15, 13, 360, 176));
			messageScroll.setViewportView(getMessageField());
		}
		return messageScroll;
	}

	/**
	 * This method initializes messageField	
	 * 	
	 * @return javax.swing.JTextArea	
	 */
	private JTextArea getMessageField() {
		if (messageField == null) {
			messageField = new JTextArea();
		}
		return messageField;
	}

	public String sendMessage() {		
		return messageField.getText();
	}

	public void setMessageAction(ActionListener listener) {
		this.submitButton.addActionListener(listener);		
	}

}
